home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / dflat_r_.arc / LISTS.C < prev    next >
Text File  |  1991-10-02  |  6KB  |  217 lines

  1. /* --------------- lists.c -------------- */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <conio.h>
  7. #include <dos.h>
  8. #include "dflat.h"
  9.  
  10. struct LinkedList Focus;
  11. struct LinkedList Built;
  12.  
  13. /* --- set focus to the window beneath the one specified --- */
  14. void SetPrevFocus(WINDOW wnd)
  15. {
  16.     if (wnd != NULLWND && wnd == inFocus)    {
  17.         WINDOW wnd1 = wnd;
  18.         while (TRUE)    {
  19.             if ((wnd1 = PrevWindow(wnd1)) == NULLWND)
  20.                 wnd1 = Focus.LastWindow;
  21.             if (wnd1 == wnd)
  22.                 return;
  23.             if (wnd1 != NULLWND)
  24.                 break;
  25.         }
  26.         if (wnd1 != NULLWND)
  27.             SendMessage(wnd1, SETFOCUS, TRUE, 0);
  28.     }
  29. }
  30.  
  31. /* this function assumes that wnd is in the Focus linked list */
  32. static WINDOW SearchFocusNext(WINDOW wnd, WINDOW pwnd)
  33. {
  34.     WINDOW wnd1 = wnd;
  35.  
  36.     if (wnd != NULLWND)    {
  37.         while (TRUE)    {
  38.             if ((wnd1 = NextWindow(wnd1)) == NULLWND)
  39.                 wnd1 = Focus.FirstWindow;
  40.             if (wnd1 == wnd)
  41.                 return NULLWND;
  42.             if (wnd1 != NULLWND)
  43.                 if (pwnd == NULLWND || pwnd == GetParent(wnd1))
  44.                     break;
  45.         }
  46.     }
  47.     return wnd1;
  48. }
  49.  
  50. /* ----- set focus to the next sibling ----- */
  51. void SetNextFocus(WINDOW wnd)
  52. {
  53.     WINDOW wnd1;
  54.  
  55.     if (wnd != inFocus)
  56.         return;
  57.     if ((wnd1 = SearchFocusNext(wnd, GetParent(wnd)))==NULLWND)
  58.         wnd1 = SearchFocusNext(wnd, NULLWND);
  59.     if (wnd1 != NULLWND)
  60.         SendMessage(wnd1, SETFOCUS, TRUE, 0);
  61. }
  62.  
  63. /* ---- remove a window from the Built linked list ---- */
  64. void RemoveBuiltWindow(WINDOW wnd)
  65. {
  66.     if (wnd != NULLWND)    {
  67.         if (PrevWindowBuilt(wnd) != NULLWND)
  68.             NextWindowBuilt(PrevWindowBuilt(wnd)) =
  69.                 NextWindowBuilt(wnd);
  70.         if (NextWindowBuilt(wnd) != NULLWND)
  71.             PrevWindowBuilt(NextWindowBuilt(wnd)) =
  72.                 PrevWindowBuilt(wnd);
  73.         if (wnd == Built.FirstWindow)
  74.             Built.FirstWindow = NextWindowBuilt(wnd);
  75.         if (wnd == Built.LastWindow)
  76.             Built.LastWindow = PrevWindowBuilt(wnd);
  77.     }
  78. }
  79.  
  80. /* ---- remove a window from the Focus linked list ---- */
  81. void RemoveFocusWindow(WINDOW wnd)
  82. {
  83.     if (wnd != NULLWND)    {
  84.         if (PrevWindow(wnd) != NULLWND)
  85.             NextWindow(PrevWindow(wnd)) = NextWindow(wnd);
  86.         if (NextWindow(wnd) != NULLWND)
  87.             PrevWindow(NextWindow(wnd)) = PrevWindow(wnd);
  88.         if (wnd == Focus.FirstWindow)
  89.             Focus.FirstWindow = NextWindow(wnd);
  90.         if (wnd == Focus.LastWindow)
  91.             Focus.LastWindow = PrevWindow(wnd);
  92.     }
  93. }
  94.  
  95. /* ---- append a window to the Built linked list ---- */
  96. void AppendBuiltWindow(WINDOW wnd)
  97. {
  98.     if (wnd != NULLWND)    {
  99.         if (Built.FirstWindow == NULLWND)
  100.             Built.FirstWindow = wnd;
  101.         if (Built.LastWindow != NULLWND)
  102.             NextWindowBuilt(Built.LastWindow) = wnd;
  103.         PrevWindowBuilt(wnd) = Built.LastWindow;
  104.         NextWindowBuilt(wnd) = NULLWND;
  105.         Built.LastWindow = wnd;
  106.     }
  107. }
  108.  
  109. /* ---- append a window to the Focus linked list ---- */
  110. void AppendFocusWindow(WINDOW wnd)
  111. {
  112.     if (wnd != NULLWND)    {
  113.         if (Focus.FirstWindow == NULLWND)
  114.             Focus.FirstWindow = wnd;
  115.         if (Focus.LastWindow != NULLWND)
  116.             NextWindow(Focus.LastWindow) = wnd;
  117.         PrevWindow(wnd) = Focus.LastWindow;
  118.         NextWindow(wnd) = NULLWND;
  119.         Focus.LastWindow = wnd;
  120.     }
  121. }
  122.  
  123. /* -------- get the first child of a parent window ------- */
  124. WINDOW GetFirstChild(WINDOW wnd)
  125. {
  126.     WINDOW ThisWindow = Built.FirstWindow;
  127.     while (ThisWindow != NULLWND)    {
  128.         if (GetParent(ThisWindow) == wnd)
  129.             break;
  130.         ThisWindow = NextWindowBuilt(ThisWindow);
  131.     }
  132.     return ThisWindow;
  133. }
  134.  
  135. /* -------- get the next child of a parent window ------- */
  136. WINDOW GetNextChild(WINDOW wnd, WINDOW ThisWindow)
  137. {
  138.     if (ThisWindow != NULLWND)    {
  139.         do    {
  140.             if ((ThisWindow = NextWindowBuilt(ThisWindow)) !=
  141.                     NULLWND)
  142.                 if (GetParent(ThisWindow) == wnd)
  143.                     break;
  144.         }    while (ThisWindow != NULLWND);
  145.     }
  146.     return ThisWindow;
  147. }
  148.  
  149. /* -- get first child of parent window from the Focus list -- */
  150. WINDOW GetFirstFocusChild(WINDOW wnd)
  151. {
  152.     WINDOW ThisWindow = Focus.FirstWindow;
  153.     while (ThisWindow != NULLWND)    {
  154.         if (GetParent(ThisWindow) == wnd)
  155.             break;
  156.         ThisWindow = NextWindow(ThisWindow);
  157.     }
  158.     return ThisWindow;
  159. }
  160.  
  161. /* -- get next child of parent window from the Focus list -- */
  162. WINDOW GetNextFocusChild(WINDOW wnd, WINDOW ThisWindow)
  163. {
  164.     while (ThisWindow != NULLWND)    {
  165.         ThisWindow = NextWindow(ThisWindow);
  166.         if (ThisWindow != NULLWND)
  167.             if (GetParent(ThisWindow) == wnd)
  168.                 break;
  169.     }
  170.     return ThisWindow;
  171. }
  172.  
  173. /* -------- get the last child of a parent window ------- */
  174. WINDOW GetLastChild(WINDOW wnd)
  175. {
  176.     WINDOW ThisWindow = Built.LastWindow;
  177.     while (ThisWindow != NULLWND)    {
  178.         if (GetParent(ThisWindow) == wnd)
  179.             break;
  180.         ThisWindow = PrevWindowBuilt(ThisWindow);
  181.     }
  182.     return ThisWindow;
  183. }
  184.  
  185. /* ------- get the previous child of a parent window ------- */
  186. WINDOW GetPrevChild(WINDOW wnd, WINDOW ThisWindow)
  187. {
  188.     if (ThisWindow != NULLWND)    {
  189.         do    {
  190.             if ((ThisWindow = PrevWindowBuilt(ThisWindow)) !=
  191.                     NULLWND)
  192.                 if (GetParent(ThisWindow) == wnd)
  193.                     break;
  194.         }    while (ThisWindow != NULLWND);
  195.     }
  196.     return ThisWindow;
  197. }
  198.  
  199. /* --- bypass system windows when stepping through focus --- */
  200. void SkipSystemWindows(int Prev)
  201. {
  202.     int cl, ct = 0;
  203.     while ((cl = GetClass(inFocus)) == MENUBAR ||
  204.             cl == APPLICATION
  205. #ifdef INCLUDE_STATUSBAR
  206.                  || cl == STATUSBAR
  207. #endif
  208.                                 )    {
  209.         if (Prev)
  210.             SetPrevFocus(inFocus);
  211.         else 
  212.             SetNextFocus(inFocus);
  213.         if (++ct == 3)
  214.             break;
  215.     }
  216. }
  217.